<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li {
            background-color: black;
            width: 200px;
            height: 30px;
            border: 1px solid red;
            list-style: none;
        }
    </style>
</head>

<body>
    <!-- ## 2.循环生成列表数据，然后使用js实现隔行变色
    ```javascript
        for(var i = 0;i < 10;i++){
            if(i % 2 === 0){
                li.style.backgroundColor = 'red';
            }else{
                li.style.backgroundColor = 'red';
            }
        }
    ``` -->

    <!-- 行: <input type="text" id="num1"> -->
    <!-- 列: <input type="text" id="num2"> -->
    <!-- <button id="btn">生成</button> -->

    <ul id="ul">

    </ul>
    <script>

       
            // var n1 = num1.value
            var res = ''
            for (var i = 0; i < 10; i++) {
                res = res + '<li></li>'
            }
            ul.innerHTML = res;
        
        
        var li = document.querySelectorAll('li');
        for (var j = 0; j < li.length; j++) {

            if (j % 2 == 0) {
                li[j].style.backgroundColor = 'red';
            } else {
                li[j].style.backgroundColor = 'yellow';
            }
        }
    </script>
</body>

</html>